/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package MVC;

import java.net.InetAddress;
import java.util.HashMap;

/**
 * ModelUser
 * The Model of the MVC pattern
 * for the modification in the list of connected user
 * @author Duy Duc, Metangmo
 */
public class ModelUser extends java.util.Observable{
    public HashMap <InetAddress,String> userList;
    
    
    /**
     * Constructor
     */
    
    public ModelUser() {       
        this.userList = new HashMap <InetAddress,String> ();        
    }
    
    /**
     * addToList:
     * function adds the new connected user in a table of (IPAddress-Nickname)
     * and notifies the Observer(ChatGUI) of the change
     * @param ipAddress
     *        IP Address of a new user
     * @param user
     *        Nickname of the user
     */
    
    public void addToList(InetAddress ipAddress,String user){
        this.userList.put(ipAddress,user);
        setChanged();
        notifyObservers(userList);
    }
    
    /**
     * removeFromList:
     * function deletes a user from the table of (IPAddress-Nickname)
     * and notifies the Observer(ChatGUI) of the change
     * @param ipAddress
     *        IP Address of the removed user
     */
    
    public void removeFromList(InetAddress ipAddress){
        this.userList.remove(ipAddress);
        setChanged();
        notifyObservers(userList);
    }
    
    
    /*
     * getListUser:
     * function collects the list of actuel connected users on the ChatSystem
     * @return
     *        List of connected user
     */
    
    public HashMap <InetAddress,String> getListUser(){
        return this.userList;
    }
}